package com.thomas.framework.utils;

import com.thomas.framework.entity.SysModel;
import com.thomas.framework.entity.SysUser;
import com.thomas.framework.service.ISysModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * Created by taohj on 2014/5/25.
 */
public class WebContext {


    @Autowired
    ISysModelService modelService;

    private SysUser admin;


    //包括功能 和 菜单 Key Value 用于验证 权限  和记录日志
    Map<String, SysModel> functions;


    public WebContext(SysUser admin) {
        this.admin = admin;
    }


    public static HttpServletRequest getHttpServletRequest() {
        ServletRequestAttributes t = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        HttpServletRequest req = t.getRequest();
        return req;
    }


    public static HttpSession getHttpSession() {
        return getHttpServletRequest().getSession();
    }


    public SysUser getAdmin() {
        return admin;
    }


    public Map<String, SysModel> getFunctions() {
        return functions;
    }

    public void setFunctions(Map<String, SysModel> functions) {
        this.functions = functions;
    }
}
